package com.charles.video.system.service.impl;

import com.charles.video.common.core.responseDomain.TableInfo;
import com.charles.video.common.core.utils.PageUtils;
import com.charles.video.system.mapper.VideoInfoMapper;
import com.charles.video.system.mapper.VideoTagMapper;
import com.charles.video.system.service.VideoInfoService;
import com.charles.video.system.vo.SearchVideoForm;
import com.charles.video.system.vo.VideoDetailVo;
import com.charles.video.system.vo.VideoTableDataVo;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Charles-H
 *
 * 视频数据接口实现
 */
@Service
public class VideoInfoServiceImpl implements VideoInfoService {

    @Resource
    private VideoInfoMapper videoInfoMapper;
    
    @Resource
    private VideoTagMapper videoTagMapper;

    @Override
    public TableInfo queryVideoTableData(Integer pageNum, Integer pageSize, SearchVideoForm searchVideoForm) {
        List<VideoTableDataVo> videoTableDataVos = videoInfoMapper.queryVideoTableData(searchVideoForm);
        List<VideoTableDataVo> packageData = (List<VideoTableDataVo>) PageUtils.startPage(videoTableDataVos, pageNum, pageSize);
        TableInfo rspData = new TableInfo();
        rspData.setCode(200);
        rspData.setRows(packageData);
        rspData.setMsg("查询成功");
        rspData.setTotal(new PageInfo(videoTableDataVos).getTotal());
        return rspData;
    }

    @Override
    public VideoDetailVo queryVideoDetail(String videoId) {
        VideoDetailVo videoDetailVo = videoInfoMapper.queryVideoDetail(videoId);
        videoDetailVo.setLabelList(videoTagMapper.queryTagList(videoId));
        return videoDetailVo;
    }
}
